<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['link_index_mb_homead'];?></h3>
      <ul class="tab-base">
        <li><a href="index.php?act=mb_homead&op=mb_homead_list" ><span><?php echo $lang['nc_manage'];?></span></a></li>
        <li><a href="index.php?act=mb_homead&op=mb_homead_add" ><span><?php echo $lang['nc_new'];?></span></a></li>
        <li><a href="JavaScript:void(0);" class="current"><span><?php echo $lang['nc_edit'];?></span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="link_form" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="id" value="<?php echo $output['link_array']['id'];?>" />
    <table class="table tb-type2">
      <tbody>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="had_title">请推荐位标题</td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['had_title'];?>" name="had_title" id="had_title" class="txt"></td>
          <td class="vatop tips">请输入推荐位标题</td>
        </tr>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="had_code">推荐位编号</td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['had_code'];?>" name="had_code" id="had_code" class="txt"></td>
          <td class="vatop tips">请输入推荐位编号</td>
        </tr>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="had_spec">图片规格</td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['had_spec'];?>" name="had_spec" id="had_spec" class="txt"></td>
          <td class="vatop tips">请输入图片规格</td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for=""><?php echo $lang['link_index_pic_sign'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <span class="type-file-show">
            <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
            <div class="type-file-preview">
              <img src="<?php echo UPLOAD_SITE_URL.DS.ATTACH_MOBILE.'/had/'.$output['link_array']['had_img'];?>"></div>
            </span>
            <span class="type-file-box">
            <input name="had_img" type="file" class="type-file-file" id="had_img" size="30">
            </span>
          </td>
          <td class="vatop tips"><?php if($output['link_array']['had_img'] != ''){ ?>
            <?php } else { echo "<span class='red'>".$lang['link_add_tosign']."</span>"; } ?></td>
        </tr>
        <tr>
          <td colspan="2" ><label for="had_url">链接地址:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <input type="text" name="had_url" id="had_url" value="<?php echo $output['link_array']['had_url'];?>" class="txt" >
          </td>
          <td class="vatop tips">指向外部链接时填写，否则不填写</td>
        </tr>
        
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="had_name">所属类型:</label></td>
        </tr>
        
        <tr class="noborder">
          <td class="vatop rowform">
            <select name="had_type" class="had_type" >
              <option <?php if($output['link_array']['had_type'] == 1){ ?>selected='selected'<?php } ?> value="1">商品分类</option>
              <option <?php if($output['link_array']['had_type'] == 2){ ?>selected='selected'<?php } ?> value="2">商品推荐</option>
              <option <?php if($output['link_array']['had_type'] == 3){ ?>selected='selected'<?php } ?> value="3">促销商品</option>
              <option <?php if($output['link_array']['had_type'] == 4){ ?>selected='selected'<?php } ?> value="4">商品标签</option>
              <option <?php if($output['link_array']['had_type'] == 5){ ?>selected='selected'<?php } ?> value="5">单商品</option>
              <option <?php if($output['link_array']['had_type'] == 0){ ?>selected='selected'<?php } ?> value="0">未知</option>
            </select>
          </td>
          <td class="vatop tips">所属类型（1分类，2商品推荐，3促销商品，4商品标签，5单商品）</td>
        </tr>
        
        <tr>
          <td colspan="2" ><label for="had_id">类型对应ID:</label></td>
        </tr>
        <tr class="noborder goods_flag"  data="1" style="display: none;">
          	<td class="vatop rowform" >

                <select class="sec_had_id" >
                	<?php foreach ($output['goods_flag']  as $key =>$val){?>
              			<option <?php if($val['flag_id'] == $output['link_array']['had_id']){ ?>selected='selected'<?php } ?> value="<?php echo $val['flag_id'];?>"><?php echo $val['flag_name']?></option>
            		<?php }?>
            	</select>
            </td>
			
          <td class="vatop tips">填写对应所属类型填写对应的ID,属于商品推荐填1，促销商品填1，商品分类填分类ID，商品标签下拉选择</td>
        </tr>
        
        <tr class="noborder had_major_id" >
          	
			<td class="vatop rowform" >
                <input  type="text" name="had_major_id" id="had_major_id" value="<?php echo $output['link_array']['had_major_id'];?>" class="txt" >

          	</td>
          <td class="vatop tips">单商品填商品ID,商品推荐填1，促销商品填1，商品分类填分类ID，商品标签下拉选择</td>
        </tr> 
        
        <tr>
          <td colspan="2" ><label for="had_id">商品ID:</label></td>
        </tr>
         <tr class="noborder had_id" >
          	
			<td class="vatop rowform" >
                <input  type="text" name="had_id" id="had_id" value="<?php echo $output['link_array']['had_id'];?>" class="txt" >

          	</td>
          <td class="vatop tips">指向商品链接时填写商品ID，否则填写0</td>
        </tr> 
        
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="had_name"><?php echo $lang['link_index_title'];?>:</label></td>
        </tr>
        
        
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['had_name'];?>" name="had_name" id="had_name" class="txt"></td>
          <td class="vatop tips"><?php echo $lang['link_add_name'];?></td>
        </tr>
        <tr>
          <td colspan="2" ><label for="had_price">价格:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <input type="text" name="had_price" id="had_price" value="<?php echo $output['link_array']['had_price'];?>" class="txt" >
          </td>
          <td class="vatop tips">价格</td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for="had_order"><?php echo $lang['nc_sort'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['had_order'];?>" name="had_order" id="had_order" class="txt"></td>
          <td class="vatop tips"><?php echo $lang['link_add_sort_tip'];?></td>
        </tr>
      <tfoot>
        <tr class="tfoot">
          <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<script>
//按钮先执行验证再提交表单
$(function(){$("#submitBtn").click(function(){
    if($("#link_form").valid()){
     $("#link_form").submit();
	}
	});
});
//
$(document).ready(function(){
	$('#link_form').validate({
        errorPlacement: function(error, element){
			error.appendTo(element.parent().parent().prev().find('td:first'));
        },
        rules : {
            had_title : {
                required : true
            },
            had_code : {
                required : true
            },
            had_name : {
                required : true
            },
            /*link_url  : {
                required : true,
                url      : true
            },*/
            had_order : {
                number   : true
            }
        },
        messages : {
            had_title : {
                required : '推荐位标题不能为空'
            },
            had_code : {
                required : '推荐位编号不能为空'
            },
            had_name : {
                required : '<?php echo $lang['link_add_title_null'];?>'
            },
            /*link_url  : {
                required : '<?php echo $lang['link_add_url_null'];?>',
                url      : '<?php echo $lang['link_add_url_wrong'];?>'
            },*/
            had_order  : {
                number   : '<?php echo $lang['link_add_sort_int'];?>'
            }
        }
    });
});
</script> 
<script type="text/javascript">
$(function(){
    var textButton="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
	$(textButton).insertBefore("#had_img");
	$("#had_img").change(function(){
	$("#textfield1").val($("#had_img").val());
});
});
</script>

<script type="text/javascript">
$(function(){
	$(".had_type").change(function(){
		$('#had_major_id').val('');
	    if($(this).val()==4){
		    
	    	$('.had_major_id').css('display','none');
			$('.goods_flag').show();
		}else{

			$('.goods_flag').css('display','none');
			$('.had_major_id').show();
		}
	  });

	  $(".sec_had_id").change(function(){
			$("#had_major_id").val($(this).val());
			
		});
});
</script>




